//
//  ViewController.m
//  MVP
//
//  Created by 刘国庆 on 2018/10/10.
//  Copyright © 2018年 刘国庆. All rights reserved.
//

#import "ViewController.h"
#import "LGQPersenter.h"
#import "LGQModel.h"

typedef void (^Blocktest)(int);
typedef int(^BlockAddTest)(int);

@interface ViewController ()<UITableViewDelegate,UITableViewDataSource,persenterDelegate>

@property (nonatomic,strong) LGQPersenter * persenter;
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray * dataArray;




@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view addSubview:self.tableView];
    
    self.persenter = [[LGQPersenter alloc] init];
    self.persenter.delegate = self;
    [self.persenter getData];
    
    
    Blocktest  blocktest = ^(int a)
    {
        NSLog(@"blocktest-->%d",a);
    };
    blocktest(3);
    
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)getUserContent:(NSArray *)array
{
    self.dataArray = [NSArray arrayWithArray:array];
    [self.tableView reloadData];
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width,  [UIScreen mainScreen].bounds.size.height) style:UITableViewStylePlain];
        _tableView.dataSource = self;
        _tableView.backgroundColor = [UIColor whiteColor];
        _tableView.delegate = self;
    }
    return _tableView;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];
    
    if (!cell)
    {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"sub"];
    }
    
    LGQModel * model = [self.dataArray objectAtIndex:indexPath.row];
    
    cell.textLabel.text = model.name;
    
    
    
    return cell;
}



@end
